﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DimensionData.Data2
{
    public class DRelationChain
    {
        public List<DRelation> Relations { get; private set; }

        public DRelationChain()
        {
            Relations = new List<DRelation>();
        }

        public void Append(DRelation relation)
        {
            if (Relations.Count > 0)
            {
                Relations.Last().NextRelation = relation;
            }

            relation.Level = Relations.Count;

            Relations.Add(relation);
        }

        public DRelation First()
        {
            return Relations.FirstOrDefault();
        }

        public DRelation Next(DRelation relation)
        {
            for (int index = 0; index < Relations.Count - 1; index++)
            {
                if (Relations[index] == relation)
                {
                    return Relations[index + 1];
                }
            }
            return null;
        }

        public DRelation Last()
        {
            return Relations.LastOrDefault();
        }
    }
}
